<?php
define("MICROTIME", microtime(TRUE));
header("Use-Compress:1");
header("Cache-Control:no-cache, must-revalidate");
header("Expires:Sat, 26 Jul 1997 05:00:00 GMT");
define("ROOT_DIR", dirname(__FILE__) . "/..");
define("CONFIG_DIR", ROOT_DIR . "/Config/");
define("CORE_DIR", ROOT_DIR . "/Core/");
define("MOD_DIR", ROOT_DIR . "/Model/");
define("CON_DIR", ROOT_DIR . "/Controller/");
define("TPL_DIR", ROOT_DIR . "/Tpl/");
define("THIRD_DIR", ROOT_DIR . "/Third/");
//载入核心文件
include CORE_DIR . 'Common.php';
$config = Common::getConfig();

//DEBUG模式 - 能直接设定用户ID和DATA数据 且PHP会报错
define('DEBUG', $config['debug']);

//入口
Application::main();

/**
 * 应用入口类
 *
 * @author Leo
 */
class Application {
    
    /**
     * 管理页面入口
     * @author zhulin
     * @since 2012.4.21
     */
    public static function main() {  
        //初始化
        try{
           //self::ini();     
        $con = empty($_GET['con']) ? 'IndexController' : ucfirst(strtolower($_GET['con'])) . 'Controller';
        $act = empty($_GET['act']) ? 'run' : $_GET['act'];
        $conFile = CON_DIR . "{$con}.php";

        if (file_exists($conFile)) {
            include $conFile;
            $object = new $con;
            if (method_exists($object, $act)) {     
               $test= $object->$act(); 
            }
        } 
        }
        catch( AppException $e ){
            include TPL_DIR . 'errorPage.php';
        }
        
        
    }

    /**
     * 初始化
     */
    public static function ini() {
        //报错   
        error_reporting(( isset($_GET['err']) && DEBUG ) ? ( E_ALL ^ E_NOTICE ) : 0 );
        //自动转义
        $magic_quotes_gpc = get_magic_quotes_gpc();
        //去除转义符 防止解析JSON出错
        if ($magic_quotes_gpc) {
            $_POST['data'] = stripslashes($_POST['data']);
        }
       
        //初始化数据  
        $_POST = json_decode($_POST['data'], true); 
            $_POST = array();
            //DEBUG下可使用GET中的DATA
            if (DEBUG && $_GET['data']) {
                //去除转义符 防止解析JSON出错
                if ($magic_quotes_gpc) { 
                    $_GET['data'] = stripslashes($_GET['data']);
                }
              
            }
        
    }

}